/**
 * Unit test for class Bishop in pieces package
 * Most of the methods that are tested in this unit test are implemented from Piece class
 * 
 * @author Dzulhafizi Abidin
 */

package unitTests;
import pieces.*;
import mainClasses.*;

import junit.framework.TestCase;



public class BishopTest extends TestCase {
	
	//initializations of several bishops on board b with different positions
	Board b = new Board();
	Bishop bishop = new Bishop(2, 0, b, "White");
	Bishop bishop1 = new Bishop(5, 0, b, "White");
	Bishop bishop2 = new Bishop(2, 3, b, "Black");
	Bishop bishop3 = new Bishop(5, 4, b, "White");
	Bishop bishop4 = new Bishop(2, 7, b, "Black");
	Bishop bishop5 = new Bishop(5, 7, b, "Black");



	/**
	 * Tests the movePossible() method in Bishop class
	 */
	public void testMovePossible() {
		
		//a list of assertions to confirm the accuracy of the bishops' movement
		assertTrue(bishop.movePossible(0,2));                     
		assertTrue(bishop1.movePossible(7,2));		
		assertTrue(bishop2.movePossible(4,5));
		assertTrue(bishop3.movePossible(6,3));
		assertTrue(bishop4.movePossible(0,5));
		assertTrue(bishop5.movePossible(7,5));
		
		assertFalse(bishop.movePossible(4,5));
		assertFalse(bishop1.movePossible(7,5));
		assertFalse(bishop2.movePossible(0,2));
		assertFalse(bishop3.movePossible(0,5));
		assertFalse(bishop4.movePossible(0,2));
		assertFalse(bishop5.movePossible(6,3));
		
	}

	
	/**
	 * Tests the constructor of the Bishop class
	 */
	public void testBishop() {
		assertTrue(bishop.getX() == 2 && bishop.getY() == 0);	
		assertFalse(bishop.getClass().equals(NullPiece.class));								
		assertTrue(bishop.getType().equals(" Bishop  "));		
		assertTrue(bishop.getSide().equals("White"));			
	}

	
	/**
	 * Tests the getX() accessor in Bishop class
	 */
	public void testGetX() {
		assertTrue(bishop.getX() == 2);
		assertTrue(bishop1.getX() == 5);
		assertTrue(bishop2.getX() == 2);
		assertTrue(bishop3.getX() == 5);
		assertTrue(bishop4.getX() == 2);
		assertTrue(bishop5.getX() == 5);
	}

	/**
	 * Tests the getY() accessor in Bishop class
	 */
	public void testGetY() {
		assertTrue(bishop.getY() == 0);
		assertTrue(bishop1.getY() == 0);
		assertTrue(bishop2.getY() == 3);
		assertTrue(bishop3.getY() == 4);
		assertTrue(bishop4.getY() == 7);
		assertTrue(bishop5.getY() == 7);
	}
	

	/**
	 * Tests the getStatus() accessor in Bishop class
	 */
	public void testGetStatus() {
		assertFalse(bishop.getClass().equals(NullPiece.class));				//confirms that bishop is not a nullPiece
		assertTrue(bishop1 instanceof Bishop);								//confirms that bishop1 is an instance of Bishop class
	}

	/**
	 * Tests the getType() accessor in Bishop class
	 */
	public void testGetType() {
		assertTrue(bishop.getType() == " Bishop  ");
		assertTrue(bishop1.getType() == " Bishop  ");
		assertTrue(bishop2.getType() == "BK-Bishop");
		assertTrue(bishop3.getType() == " Bishop  ");
		assertTrue(bishop4.getType() == "BK-Bishop");
		assertTrue(bishop5.getType() == "BK-Bishop");
	}

	/**
	 * Tests the getSide() accessor in Bishop class
	 */
	public void testGetSide() {
		assertTrue(bishop.getSide() == "White");
		assertTrue(bishop1.getSide() == "White");
		assertTrue(bishop2.getSide() == "Black");
		assertTrue(bishop3.getSide() == "White");
		assertTrue(bishop4.getSide() == "Black");
		assertTrue(bishop5.getSide() == "Black");
	}

	/**
	 * Tests the setType() mutator in Bishop class
	 */
	public void testSetType() {
		bishop.setType("Yellow");					//sets the type of bishop to "Yellow"
		assertTrue(bishop.getType() == "Yellow");   //checks whether the type is changed or not
		bishop.setType(" Bishop  ");				//sets the type back to " Bishop  "
	}

	/**
	 * Tests the isEqual() method in Bishop class
	 */
	public void testIsEqual() {
		Bishop bishopX = new Bishop (2,0,b,"White");		//creates a new Bishop with the same attributes as bishop
		assertTrue(bishop.isEqual(bishopX));				//confirms the equality between the two bishops
	}

	/**
	 * Tests the move() method in Piece class, implemented by Bishop class. The two kings have to be added to 
	 * the board because a feature of the board class doesn't allow any movement on the board if there's no 
	 * king or only one on it. Several different movements are called on the bishop and this test confirms the 
	 * accuracy of the move() method in Piece class.
	 * 
	 * The bishop will only move to the desired Point if it's legal.
	 */
	public void testMove() {
		Board b1 = new Board();
		int origin = 0;
		Bishop newBishop = new Bishop(0, 0, b1, "White");
		King king1 = new King(0, 3, b1, "White");
		King king2 = new King(7, 4, b1, "Black");
		b1.add(newBishop);
		b1.add(king1);
		b1.add(king2);
		
		newBishop.move(3,4);
		assertTrue(newBishop.getX() == origin && newBishop.getY() == origin);
		
		
		newBishop.move(2,2);
		assertTrue(newBishop.getX() == 2 && newBishop.getY() == 2);
		newBishop.move(origin,origin);
		
		
		newBishop.move(7,7);
		assertTrue(newBishop.getX() == 7 && newBishop.getY() == 7);
		newBishop.move(origin,origin);
		
		
		newBishop.move(4,4);
		assertTrue(newBishop.getX() == 4 && newBishop.getY() == 4);
		newBishop.move(origin,origin);
		
		
		newBishop.move(5,2);
		assertTrue(newBishop.getX() == origin && newBishop.getY() == origin);
		
		
		newBishop.move(2,2);
		assertTrue(newBishop.getX() == 2 && newBishop.getY() == 2);
		newBishop.move(origin,origin);
		
		
	}

	/**
	 * Tests the changePosition() mutator in Bishop class
	 */
	public void testChangePosition() {
		//Point newP = new Point(7,7);
		int dest = 7;
		bishop.changePosition(dest, dest);						//changes the position of the bishop
		assertTrue(bishop.getX() == 7 && bishop.getY() == 7);			//confirms that the position has been changed
			
		bishop.changePosition(2,0);				//puts the bishop back to its origin
	}

}
